package com.boe.csb.web.controller.csb;

import com.alibaba.csb.console.sdk.Result;
import com.alibaba.fastjson.JSONObject;
import com.boe.csb.core.service.csb.CsbAuditOrderService;
import com.boe.csb.web.controller.BaseController;
import com.boe.csb.web.model.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by tianxiang.luo on 16/12/4.
 * 1.用户审核订单
 */
@RestController
@RequestMapping("/api/audit/order")
public class CsbAuditOrderController extends BaseController {


    @Autowired
    private CsbAuditOrderService csbAuditOrderService;

    /**
     * 查看审核列表 根据serviceId  审核订单
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResultModel<Result> auditOrdersList(HttpSession session,
                                               @RequestParam Integer pageNum,
                                               String serviceId,
                                               String onlyPending,
                                               String serviceName,
                                               String alias) {
        String userId = fetchUserId(session);
        boolean stat = "true".equals(onlyPending);
        return ResultModel.success(csbAuditOrderService.orderList(userId, serviceId, pageNum, stat, serviceName,alias));
    }


    /**
     * 审核订单,通过
     */
    @RequestMapping(value = "/allow", method = RequestMethod.POST)
    public ResultModel<Result> auditOrder(HttpSession session, @RequestBody JSONObject data) {
        String userId = fetchUserId(session);
        return ResultModel.success(csbAuditOrderService.auditOrder(userId, data));
    }



}
